<!DOCTYPE html>

<meta charset="utf-8" />	

<form class="form-horizontal" role="form"  onsubmit="return submitForm(this);"
 action="mpamng/term/eidtTermFee.do" id="termFee_form">
 	<input type="hidden" id="type" name="type" />
 	<input type="hidden" id="feeCode" name="feeCode" />
 	<input type="hidden" id="terminalId" name="terminalId" />
	<!-- #section:elements.form -->
	<br/>
	<div class="form-group">
		<label class="col-sm-2 control-label no-pEditing-right"for="form-field-1"> 合作商编号 </label>
		<div class="col-sm-8">
			<input type="text" id="agentId" name="agentId" placeholder="合作商编号" class="col-xs-10 col-sm-7" readonly="readonly"/>
		</div>
	</div>

	<div class="form-group">
		<label class="col-sm-2 control-label no-padding-right" for="form-field-1"> 终端物理号 </label>
		<div class="col-sm-8">
			<input type="text" id="terminalNo" name="terminalNo" placeholder="终端物理号" class="col-xs-10 col-sm-5" readonly="readonly"/>
		</div>
	</div>
	
	<div class="form-group">
		<label class="col-sm-2 control-label no-padding-right">
			民生类(%)： </label>
		<div class="col-sm-3">
			<input type="text" id="rateLivelihood" name="rateLivelihood" placeholder="民生类(0.38%)" validate="true"
				class="col-xs-12 col-sm-12 feecheck" value="" />
		</div>
	</div>
	
	<div class="form-group">
		<label class="col-sm-2 control-label no-padding-right">
			一般类(%)： </label>
		<div class="col-sm-3">
			<input type="text" id="rateGeneral" name="rateGeneral" placeholder="一般类(0.78%)" validate="true"
				class="col-xs-12 col-sm-12 feecheck" value="" />
		</div>
	</div>
	
	<div class="form-group">
		<label class="col-sm-2 control-label no-padding-right">
			餐娱类(%)： </label>
		<div class="col-sm-3">
			<input type="text" id="rateEntertain" name="rateEntertain" placeholder="餐娱类(1.25%)" validate="true"
				class="col-xs-12 col-sm-12 feecheck" value="" datatype="money"/>
		</div>
	</div>
	
	<div class="form-group">
		<label class="col-sm-2 control-label no-padding-right">
			批发类(%)： </label>
		<div class="col-sm-3">
			<input type="text" id="rateGeneralTop" name="rateGeneralTop" placeholder="批发类(0.78%)" validate="true"
				class="col-xs-12 col-sm-12 feecheck" value="" />
		</div>
		<label class="col-sm-2 control-label no-padding-right">
			批发类封顶(元)： </label>
		<div class="col-sm-3">
			<input type="text" id="rateGeneralMaximun" name="rateGeneralMaximun" placeholder="批发类封顶(0.78%，单位元)" validate="true"
				class="col-xs-12 col-sm-12 feecheck" value="" datatype="money"/>
		</div>
	</div>
	
	<div class="form-group">
		<label class="col-sm-2 control-label no-padding-right">
			房产类(%)： </label>
		<div class="col-sm-3">
			<input type="text" id="rateEntertainTop" name="rateEntertainTop" placeholder="房产类封顶(1.25%)" validate="true"
				class="col-xs-12 col-sm-12 feecheck" value="" datatype="money"/>
		</div>
		<label class="col-sm-2 control-label no-padding-right">
			房产类封顶(元)： </label>
		<div class="col-sm-3">
			<input type="text" id="rateEntertainMaximun" name="rateEntertainMaximun" placeholder="房产类封顶(1.25%，单位元)" validate="true"
				class="col-xs-12 col-sm-12 feecheck" value="" datatype="money"/>
		</div>
	</div>
	
	
	<div class="form-group">
		
	</div>
	
	<br/><br/>
	<div class="form-actions align-right  form-button-box" style="margin-top: 10px">
		<button class="btn" type="button" onclick="javascript:dialog.closeById('dlg-termFeeEdit');">关闭</button>
	</div>
	
</form>
<script type="text/javascript">
var agentInf;
  
$(document).ready(function() {
	setTimeout(setType, 100);
}); 

/**
 * 提示
 * @param $id  校验对象
 * @param tmsg 提示信息
 */
function TDTips($id,tmsg){
	 $id.tips({
			side:3,
	        msg:tmsg,
	        bg:'#E3C94C',
	        time:2
		 });
		 $id.focus();
}

function setType(){
	if($("#type").val()=='view'){
		$("#save").remove();
		$("#termFee_form input[type=text]").attr("readonly","readonly");
		$("#termFee_form input[type=text]").attr("placeholder","");
	}
}

function getAgentFee(agentId){
	$.ajax({
		type : "post",
		url : "mpamng/agent/queryAgentById.do",
		data:{agentId:agentId},
		dataType : 'json',
		async:false,
		success : function(result) {
			if (result.rspcod != 200) {
				//msg.alert("错误", result.rspmsg + " 错误代码："+ result.rspcod, 'error');
				return false;
			} else {
				agentInf=result.obj;
			}
		},
		error : function(XMLHttpRequest, textStatus) {
			//msg.alert("错误", "错误代码：" + XMLHttpRequest.status + ",错误描述："+ textStatus, 'error');
			return false;
		}
	});
	return true;
}

function feeCheck($id){
	var thisName = $id.attr('name');
	var thisValue = $id.val();
	//比较 民生类
	if(thisName=='rateLivelihood'){
		if(agentInf.rateLivelihood>thisValue){
			TDTips($id,"民生类费率不能小于合作商费率！");
			return false;
		}
	}
	
	//比较 一般类
	if(thisName=='rateGeneral'){
		if(agentInf.rateGeneral>thisValue){
			TDTips($id,"一般类费率不能小于合作商费率！");
			return false;
		}
	}

	//批发类
	if(thisName=='rateGeneralTop'){
		if(agentInf.rateGeneralTop>thisValue){
			TDTips($id,"批发类费率不能小于合作商费率！");
			return false;
		}
	}
	
	//批发类费率
	if(thisName=='rateGeneralMaximun'){
		if(agentInf.rateGeneralMaximun>thisValue){
			TDTips($id,"批发类费率封顶不能小于合作商费率！");
			return false;
		}
	}
	
	//比较 餐娱类
	if(thisName=='rateEntertain'){
		if(agentInf.rateEntertain>thisValue){
			TDTips($id,"餐娱类费率不能小于合作商费率！");
			return false;
		}
	}
	
	//房产类
	if(thisName=='rateEntertainTop'){
		if(agentInf.rateEntertainTop>thisValue){
			TDTips($id,"房产类费率不能小于合作商费率！");
			return false;
		}
	}
	
	//房产类
	if(thisName=='rateEntertainMaximun'){
		if(agentInf.rateEntertainMaximun>thisValue){
			TDTips($id,"房产类费率封顶不能小于合作商费率！");
			return false;
		}
	}
	return true;
}

function submitForm(obj){
	var agentId=$("#agentId").val();
	getAgentFee(agentId);
	//验证费率 
	var bool = true;
	$("input[class~='feecheck']").each(function(){
		bool = feeCheck( $(this));
		if(!bool){
			bool=false;
			return bool;
		}
	});
	if(!bool){
		return false;
	}
	return validateCallback(obj,editUserDone);
}

function editUserDone(result){
	if(result.rspcod== 200){
		msg.alert("提示",result.rspmsg,'correct');
		$("#grid-table").trigger("reloadGrid");
		dialog.closeById('dlg-termFeeEdit');
	}else{
		msg.alert("错误",result.rspmsg+" 错误代码："+result.rspcod,'error');
	}
}

</script>
